
import 'package:flutter/material.dart';
import 'package:juju/conf/IMConf.dart';
import 'package:juju/fake/fake_message_tool.dart';
import 'package:juju/model/EventQueueModel.dart';
import 'package:juju/model/UserInfoModel.dart';

class SettingPage extends StatelessWidget {
  const SettingPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: <Widget>[
          GestureDetector(
            child: Container(
              decoration: const BoxDecoration(
                  border: Border(
                      bottom: BorderSide(color: Colors.grey, width: 2.0))),
              child: const Center(
                child: Padding(
                  padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
                  child: Text(
                    "退出",
                    style: TextStyle(
                      fontSize: 18.0,
                    ),
                  ),
                ),
              ),
            ),
            onTap: () {
              _logoutAction(context: context);
            },
          ),
        ],
      ),
    );
  }

  ///========================================
  /// 退出登录
  ///========================================
  void _logoutAction({BuildContext? context}) async {
    print("======================= LogOut =====================");
    IMConf.getInstance().getJmessage().logout();
    print("======================= LogOut =====================");
    UserInfo? jmUserInfo =
        await IMConf.getInstance().getJmessage().getMyInfo();
    if (jmUserInfo == null) {
      print(" ===== 您已退出 ===== \n【获取登录用户信息】null");
      UserInfoModel.getInstance().login = false;
      EventQueueModel.getInstance().fieldClear();
      //临时用清空路由栈处理
      Navigator.of(context!)
          // .pushNamed("Welcome");
          .pushNamedAndRemoveUntil("Welcome", (route) => false);
      // .pushReplacementNamed("Welcome");
      // .pushNamedAndRemoveUntil("Welcome", ModalRoute.withName("/"));
    } else {
      print(" ===== 您已经登录 ===== \n【获取登录用户信息】${jmUserInfo.toJson()}");
    }
  }
}
